﻿using System.IO;
using System.IO.IsolatedStorage;
using System.Xml.Serialization;

namespace InstantWatch {
	public class AuthTokens {
		public string ConsumerKey { get; set; }
		public string ConsumerSecret { get; set; }

		public string UserKey { get; set; }
		public string UserSecret { get; set; }

		public string UserId { get; set; }

		public static AuthTokens Load() {
			XmlSerializer xs = new XmlSerializer(typeof(AuthTokens));

			using (IsolatedStorageFile storFile = IsolatedStorageFile.GetUserStoreForDomain())
			using (var isoFileStream = storFile.OpenFile("Tokens.xml", FileMode.Open)) {
				object tokens = xs.Deserialize(isoFileStream);
				return tokens as AuthTokens;
			}
		}

		public void Save() {
			XmlSerializer xs = new XmlSerializer(typeof(AuthTokens));

			using (IsolatedStorageFile storFile = IsolatedStorageFile.GetUserStoreForDomain())
			using (var isoFileStream = storFile.OpenFile("Tokens.xml", FileMode.OpenOrCreate)) {
				xs.Serialize(isoFileStream, this);
			}

		}
	}
}
